<?php

/**
 * @name: HOTN AnimeList
 * @author: HammerOnTheNail
 * @link: http://code.google.com/p/hotnanimelist/
 */

// Admin oldal címének meghatározása
$title .= " \ ".HOTN_ANIMELIST_ADMIN_MENU_MANGA_NEW;
$text = "";

// hozzáadása
if ($_POST['action'] == "new")
{
	require_once(e_HANDLER."upload_handler.php");
	
	$sql->db_Select("hotn_animelist_project","`project_folder`","`project_id` = '".$_POST['project_id']."'");
	$data = $sql->db_Fetch();
	
	$uploaded = process_uploaded_files(e_PLUGIN."hotn_animelist/Project/".$data['project_folder'], "unique", array('file_array_name'=>"manga_image"));
	$add = array(
		"project_id" => $_POST['project_id'],
		"category_name" => $_POST['manga_name'],
	);
	if ($uploaded[0]['error'] == 0)
	{
		$add['category_image'] = $uploaded[0]['name'];
	}
	$sql->db_Insert("hotn_animelist_category",$add);
}

// Projectek
	$sql->db_Select("hotn_animelist_project", "project_id, project_name, project_mode, project_type", "`project_mode` = 'active' and `project_type` = 'manga' ORDER BY project_name ASC");
	while ($row = $sql->db_Fetch())
	{
		if ($row['project_type'] == "manga") $row['project_type'] = HOTN_ANIMELIST_DEFAULT_MANGA;

			$project_active[$row['project_id']] = $row['project_name']." (".$row['project_type'].")";
	}
	
	$project = array(
		HOTN_ANIMELIST_ANIMETYPE_ACTIVE => $project_active
	); 
// Alap adatok
	$data = array(
		"type" => "file_form",
		"method" => "post",
		"action" =>  e_SELF."?manga.new",
		"hidden" => array("action"=>"new"),
		"data" => array(
					array(
						"type" => "select",
						"name" => "project_id",
						"group" => "true",
						"selected" => 0,
						"show" => true,
						"value" => $project,
						"text" => HOTN_ANIMELIST_ADMIN_FILE_PROJECT_NAME
					),
					array(
						"type" => "text",
						"name" => "manga_name",
						"text" => HOTN_ANIMELIST_ADMIN_MANGA_CATEGORY_MANGA_NAME
					),
					array(
						"type" => "image",
						"name" => "manga_image[]",
						"text" => HOTN_ANIMELIST_ADMIN_MANGA_CATEGORY_MANGA_IMAGE
					),
					array(
						"type" => "submit",
						"value" => HOTN_ANIMELIST_DEFAULT_FORM_ADD
					)
		)
	);

// Admin oldal tartalmának megjelenítése
$text .= "<div style='text-align: center;'>".$HOTN_ANIMELIST_FORM->show_form($data)."</div>";
?>